package it.patterns;

import it.patterns.creational.abstractfactory.AbstractFactory;
import it.patterns.creational.abstractfactory.AbstractFactory_Alternative;
import it.patterns.creational.abstractfactory.ConcreteFactoryA;
import it.patterns.creational.abstractfactory.ConcreteFactoryB;
import it.patterns.creational.abstractfactory.ConcreteFactory_Alternative;
import it.patterns.creational.builder.Builder;
import it.patterns.creational.builder.ConcreteBuilderA;
import it.patterns.creational.builder.ConcreteBuilderB;
import it.patterns.creational.builder.Director;
import it.patterns.creational.factorymethod.FactoryMethodCreator;
import it.patterns.creational.factorymethod.FactoryMethodCreatorA;
import it.patterns.creational.factorymethod.FactoryMethodCreatorB;
import it.patterns.creational.prototype.Client;
import it.patterns.creational.singleton.Singleton;

public class TestCreational {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		System.out.println("Design Patterns Test\n");

		System.out
				.println("********************************************************");
		System.out.println("Abstract Factory");
		System.out
				.println("********************************************************");
		AbstractFactory factory = new ConcreteFactoryA();
		System.out.println(factory.createProduct().getName());
		factory = new ConcreteFactoryB();
		System.out.println(factory.createProduct().getName());

		System.out.println("\nAbstract Factory Alternative");
		ConcreteFactory_Alternative factoryAlt = new ConcreteFactory_Alternative();
		System.out.println(factoryAlt.createProduct(
				AbstractFactory_Alternative.TYPE_A).getName());
		System.out.println(factoryAlt.createProduct(
				AbstractFactory_Alternative.TYPE_B).getName());

		System.out.println("\n");
		System.out
				.println("********************************************************");
		System.out.println("Builder");
		System.out
				.println("********************************************************");
		Builder builder = new ConcreteBuilderA();
		System.out.println(Director.getModel(builder));
		builder = new ConcreteBuilderB();
		System.out.println(Director.getModel(builder));

		System.out.println("\n");
		System.out
				.println("********************************************************");
		System.out.println("Factory Method");
		System.out
				.println("********************************************************");
		FactoryMethodCreator creator = new FactoryMethodCreatorA();
		System.out.println(creator.factoryMethod().getType());
		creator = new FactoryMethodCreatorB();
		System.out.println(creator.factoryMethod().getType());

		System.out.println("\n");
		System.out
				.println("********************************************************");
		System.out.println("Prototype");
		System.out
				.println("********************************************************");
		Client.doPrototype();
		System.out.println("\n");
		System.out
				.println("********************************************************");
		System.out.println("Singleton");
		System.out
				.println("********************************************************");
		Singleton instance = Singleton.getInstance();
		System.out.println(instance.getData());
		instance.setData("My Data");
		System.out.println(instance.getData());
		instance.setData("New Data");
		System.out.println(instance.getData());
	}

}
